<?php
include_once("a_checkLogin.php");
include_once("a_getLoginInfo.php");

if (!isset($_GET['petid']) || $_GET['petid'] == '') {
    die("<script>alert('传参失败！');history.go(-1);</script>");
}
include_once("conn.php");
$petid = $_GET['petid'];

$select_petinfo = "SELECT * FROM pet_infos LEFT JOIN user_infos ON pet_infos.user_ID = user_infos.user_ID WHERE pet_ID = '" . $petid . "'";
$select_casesinfo = "SELECT * FROM cases_infos WHERE cases_petID = '" . $petid . "'";

$result_petinfo = mysqli_query($connect_DB, $select_petinfo);
$result_casesinfo = mysqli_query($connect_DB, $select_casesinfo);

if ($result_petinfo) {
    $row_petinfo = mysqli_fetch_object($result_petinfo);
}

$countcases = 0;
if ($result_casesinfo) {
    $countcases = mysqli_num_rows($result_casesinfo);
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="../public/pic/f.png" type="image/x-icon">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>管理员·用户宠物病例信息</title>
    <link rel="stylesheet" href="../public/css/bootstrap.min.css">
    <script src="../public/js/bootstrap.bundle.min.js"></script>
    <link rel="stylesheet" href="../public/css/adm_public.css">
    <link rel="stylesheet" href="css/adminControlPetCasesInfo.css">
    <script src="js/adminControlPetCasesInfo.js"></script>
</head>

<body>
    <header class="fixed-top">
        <nav class="navbar navbar-expand-lg nav-top fixed-top">
            <div class="container-fluid">
                <div class="logo-div">
                    <img src="../public/pic/logo-h-w.png">
                </div>
                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                        <li class="nav-item">
                            <a class="nav-link" href="admin_PersonBasicInfo.php">个人基本信息</a>
                        </li>
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown"
                                aria-expanded="false">
                                医生管理
                            </a>
                            <ul class="dropdown-menu">
                                <li><a class="dropdown-item" href="admin_AddDoctor.php">新增医生信息</a></li>
                                <li>
                                    <hr class="dropdown-divider">
                                </li>
                                <li><a class="dropdown-item" href="javascript:void(0);">医生信息检索</a></li>
                                <li>
                                    <hr class="dropdown-divider">
                                </li>
                                <li><a class="dropdown-item" href="admin_CreateResetKey.php">重置密码密钥</a></li>
                                <li>
                                    <hr class="dropdown-divider">
                                </li>
                                <li><a class="dropdown-item" href="admin_DepartmentControl.php">医生科室管理</a></li>
                            </ul>
                        </li>
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle active" aria-current="page" role="button"
                                data-bs-toggle="dropdown" aria-expanded="false">
                                用户管理
                            </a>
                            <ul class="dropdown-menu">
                                <li><a class="dropdown-item" href="admin_SearchUserInfo.php">用户信息检索</a></li>
                                <li>
                                    <hr class="dropdown-divider">
                                </li>
                                <li><a class="dropdown-item" href="admin_DealDelAccount.php">用户注销审核</a></li>
                            </ul>
                        </li>
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown"
                                aria-expanded="false">
                                预约管理
                            </a>
                            <ul class="dropdown-menu">
                                <li><a class="dropdown-item" href="admin_ControlDepartments.php">预约科室信息管理</a></li>
                                <li>
                                    <hr class="dropdown-divider">
                                </li>
                                <li><a class="dropdown-item" href="admin_ControlDieOrders.php">超时信息处理</a></li>
                            </ul>
                        </li>
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown"
                                aria-expanded="false">
                                用户主页管理
                            </a>
                            <ul class="dropdown-menu">
                                <li><a class="dropdown-item" href="admin_ControlTips.php">健康知识模块管理</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
                <div class="info-div">
                    <p>
                        <b>当前登录： </b>
                        <name>
                            <?php echo $admin_Name; ?>
                        </name>| 
                        <a href="admin_Logout.php">退出</a>
                    </p>
                </div>
            </div>
        </nav>
    </header>
    <main>
        <!-- 导航栏 -->
        <div class="main-top-nav">
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb">
                    <li class="li-first">当前位置>>></li>
                    <li class="breadcrumb-item"><a href="javascript:void(0);">用户管理</a></li>
                    <li class="breadcrumb-item"><a href="admin_SearchUserInfo.php">用户信息检索</a></li>
                    <li class="breadcrumb-item"><a href="javascript:void(0);">用户信息详情</a></li>
                    <li class="breadcrumb-item active"><a href="javascript:void(0);">宠物病例信息</a></li>
                </ol>
                <div class="now-time-div" id="nowtime"></div>
                <script src="../public/js/getnowtime.js"></script>
            </nav>
        </div>

        <div class="main-content-div">
            <a href='admin_ControlUserInfo.php?userID=<?php echo $row_petinfo->user_ID; ?>'><button type='button'
                    class='back-btn'>点此返回</button></a>
            <div class='pet-info-div'>
                <?php
                if ($result_petinfo) {
                    echo "
                    <h4>宠 物 病 例 信 息 （共" . $countcases . "条）</h4>
                    <div class='pet-info-content-div'>
                        <p>宠物ID：" . $row_petinfo->pet_ID . "</p>
                        <p>昵称：" . $row_petinfo->pet_Name . "</p>
                        <p>宠物类型：" . $row_petinfo->pet_Type . "</p>
                        <p>主人昵称：" . $row_petinfo->user_Name . "</p>
                    </div> ";
                } else {
                    echo "<div class='pet-info-content-div'>查询错误：" . $select_petinfo . "</div>";
                }
                ?>

            </div>
            <div class='cases-info-div'>
                <div class='cases-info-top'>
                    <div class='opts'>ID</div>
                    <div class='opts'>时间</div>
                    <div class='opts'>医生</div>
                    <div class='opts'>服务</div>
                    <div class='opts'>详情</div>
                </div>
                <div class='cases-info-content'>
                    <?php
                    if ($result_casesinfo) {
                        $count = 1;
                        while ($row_casesinfo = mysqli_fetch_object($result_casesinfo)) {
                            echo "
                                <div class='info-content' id='" . $count . "'>
                                    <div class='opts'>" . $row_casesinfo->cases_ID . "</div>
                                    <div class='opts'>" . $row_casesinfo->cases_date . "</div>
                                    <div class='opts'>" . $row_casesinfo->cases_docName . "</div>
                                    <div class='opts'>" . $row_casesinfo->cases_orderType . "</div>
                                    <div class='opts xq'>查看详情</div>
                                </div> ";
                            $count++;
                        }
                    } else {
                        echo "<div class='info-content'>查询错误：" . $select_casesinfo . "</div>";
                    }
                    ?>
                </div>
            </div>
    </main>
    <footer>
        <p>&copy; 2025 ANIMAL HOME PET HOSPITAL. All rights reserved.</p>
    </footer>
    <script>

    </script>
</body>

</html>